﻿/*
    Copyright (C) <2007-2013> Kay Diefenthal

    SimpleRadio is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    SimpleRadio is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with SimpleRadio.  If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections;
using Microsoft.MediaCenter.UI;

namespace SimpleRadio
{
    /// <summary>
    /// <see cref="Service"/> Class.
    /// </summary>
    public class Service : ModelItem
    {
        #region Private Fields

        private String _displayName;
        private String _country;
        private String _region;
        private String _mediaPath;
        private String _logoPath;
        private IList _genres;
        private Boolean _isFavorite;
        private Image _logo;

        #endregion

        #region Constructors

        /// <summary>
        /// Initialize a new Instance of <see cref="Service"/> Class
        /// </summary>
        public Service()
        {

        }

        #endregion

        #region Properties

        /// <summary>
        /// The DisplayName of the Service
        /// </summary>
        public String DisplayName
        {
            get
            {
                if (string.IsNullOrEmpty(_displayName))
                    return string.Empty;
                return _displayName;
            }
            set
            {
                if (_displayName != value)
                {
                    _displayName = value;
                    FirePropertyChanged("DisplayName");
                }
            }
        }

        /// <summary>
        /// The Country of the Service
        /// </summary>
        public String Country
        {
            get
            {
                if (string.IsNullOrEmpty(_country))
                    return string.Empty;
                return _country;
            }
            set
            {
                if (_country != value)
                {
                    _country = value;
                    FirePropertyChanged("Country");
                }
            }
        }

        /// <summary>
        /// The Region of the Service
        /// </summary>
        public String Region
        {
            get
            {
                if (string.IsNullOrEmpty(_region))
                    return string.Empty;
                return _region;
            }
            set
            {
                if (_region != value)
                {
                    _region = value;
                    FirePropertyChanged("Region");
                }
            }
        }

        /// <summary>
        /// The MediaPath of the Service
        /// </summary>
        public String MediaPath
        {
            get
            {
                if (string.IsNullOrEmpty(_mediaPath))
                    return string.Empty;
                return _mediaPath;
            }
            set
            {
                if (_mediaPath != value)
                {
                    _mediaPath = value;
                    FirePropertyChanged("MediaPath");
                }
            }
        }

        /// <summary>
        /// The LogoPath of the Service
        /// </summary>
        public String LogoPath
        {
            get
            {
                if (string.IsNullOrEmpty(_logoPath))
                    return string.Empty;
                return _logoPath;
            }
            set
            {
                if (_logoPath != value)
                {
                    _logoPath = value;
                    FirePropertyChanged("LogoPath");
                }
            }
        }

        /// <summary>
        /// The Logo of the Service
        /// </summary>
        public Image Logo
        {
            get
            {
                if (_logoPath == "")
                {
                    _logo = null;
                }
                else
                {
                    _logo = new Image(_logoPath);
                }

                return _logo;
            }
            set
            {
                if (_logo != value)
                {
                    _logo = value;
                    FirePropertyChanged("Logo");
                }
            }
        }

        /// <summary>
        /// The Genres of the Service
        /// </summary>
        public IList Genres
        {
            get { return _genres; }
            set { _genres = value; }
        }

        /// <summary>
        /// The Genre of the Service
        /// </summary>
        public String Genre
        {
            get
            {
                var value = string.Empty;
                if (_genres != null)
                {
                    switch (_genres.Count)
                    {
                        case 1:
                            value = string.Format("{0}", _genres[0]);
                            break;
                        case 2:
                            value = string.Format("{0}{1}", _genres[0] + ", ", _genres[1]);
                            break;
                        case 3:
                            value = string.Format("{0}{1}{2}", _genres[0] + ", ", _genres[1] + ", ", _genres[2]);
                            break;
                        case 4:
                            value = string.Format("{0}{1}{2}{3}", _genres[0] + ", ", _genres[1] + ", ", _genres[2] + ", ",
                                                  _genres[3]);
                            break;
                        case 5:
                            value = string.Format("{0}{1}{2}{3}{4}", _genres[0] + ", ", _genres[1] + ", ", _genres[2] + ", ",
                                                  _genres[3] + ", ", _genres[4]);
                            break;

                    }
                }
                if ((_genres == null) || (_genres.Count == -1))
                {
                    value = string.Empty;
                }

                return value;
            }

        }

        /// <summary>
        /// The IsFavorite of the Service
        /// </summary>
        public Boolean IsFavorite
        {
            get { return _isFavorite; }
            set { _isFavorite = value; }
        }

        #endregion
    }
}